package com.ppch.zerocodegenerator.config;

import dev.langchain4j.model.chat.StreamingChatModel;
import dev.langchain4j.model.openai.OpenAiStreamingChatModel;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import java.time.Duration;

/**
 * Package:ZeroCodeGenerator
 * ClassName:ReasoningStreamingChatModelConfig
 *
 * @Author 泡泡茶壶
 * @Create 2025/10/15 14:28
 * @Version 1.0
 * Description:
 * 流式深度思考模型配置（使用deepseek-reasoner模型，之前是使用deepseek-chat模型）
 * deepseek-chat:默认 4K，最大 8K
 * deepseek-reasoner:默认 32K，最大 64K
 */
@ConfigurationProperties(prefix = "langchain4j.open-ai.reasoning-streaming-chat-model")
@Configuration
@Data
public class ReasoningStreamingChatModelConfig {

    private String baseUrl;

    private String apiKey;

    private String modelName;

    private Integer maxTokens;

    private Double temperature;

    private Boolean logRequests = false;

    private Boolean logResponses = false;

    /**
     * 创建基于DeepSeek的流式深度推理模型：deepseek-reasoner
     * TODO：测试时还是使用deepseek-chat模型，节约成本
     * @return StreamingChatModel
     */
    @Bean
    @Scope("prototype")
    public StreamingChatModel reasoningStreamingChatModelPrototype() {
        return OpenAiStreamingChatModel.builder()
                .apiKey(apiKey)
                .baseUrl(baseUrl)
                .modelName(modelName)
                .maxTokens(maxTokens)
                .temperature(temperature)
                .logRequests(logRequests)
                .logResponses(logResponses)
                //.returnThinking(true)
                .build();
    }

}
